package com.zxinlee.m2;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class Consumer {
    public static void main(String[] args) throws MQClientException {

        //创建消费者
        DefaultMQPushConsumer consumer02 = new DefaultMQPushConsumer("consumer02");

        //设置name server
        consumer02.setNamesrvAddr("192.168.64.141:9876");

        //订阅
        consumer02.subscribe("Topic02","*");

        //设置单线程监听器
        consumer02.setMessageListener((MessageListenerOrderly) (msgs, context) -> {
            for (MessageExt msg : msgs) {
                System.out.println("收到消息"+new String(msg.getBody()));
            }
            return ConsumeOrderlyStatus.SUCCESS;
        });

        //启动
        consumer02.start();
    }
}
